package com.sunlands.zlcx.usercenter.service.status.common;

import com.sunlands.zlcx.usercenter.common.annotation.AutoLog;
import com.sunlands.zlcx.usercenter.domain.UsersStudyInfoDO;
import com.sunlands.zlcx.usercenter.exception.BusinessException;
import com.sunlands.zlcx.usercenter.service.status.DeleteTarget;
import com.sunlands.zlcx.usercenter.service.status.*;
import com.sunlands.zlcx.usercenter.util.SpringContextHolder;
import org.springframework.stereotype.Service;

import static com.sunlands.zlcx.usercenter.vo.CommonResultMessage.STATUS_HANDLER_ERROR;

@Service
public class StatusContextFactory {

    @AutoLog
    public StatusContext fetchStatusContext(UsersStudyInfoDO.TypeEnums typeEnums){
        StatusContext statusContext = SpringContextHolder.getBean(StatusContext.class);
        switch (typeEnums){
            case ORDERNARY_COUNT_TIME:
                statusContext.setTypeStatus(SpringContextHolder.getBean(OrdernaryCountTime.class));
                break;
            case LIAN_MAI:
                statusContext.setTypeStatus(SpringContextHolder.getBean(LianMaiCountTime.class));
                break;
            case ORDERNARY_COUNT_TIME_START:
                statusContext.setTypeStatus(SpringContextHolder.getBean(OrdernaryStartLearn.class));
                break;
            case ORDERNARY_COUNT_TIME_PAUSE:
                statusContext.setTypeStatus(SpringContextHolder.getBean(OrdernaryLearnPause.class));
                break;
            case ORDERNARY_COUNT_TIME_CONTINUE:
                statusContext.setTypeStatus(SpringContextHolder.getBean(OrdernaryLearnContinue.class));
                break;
            case LIAN_MAI_START:
                statusContext.setTypeStatus(SpringContextHolder.getBean(LianMaiStartLearn.class));
                break;
            case SELECT_TARGET:
                statusContext.setTypeStatus(SpringContextHolder.getBean(SelectTarget.class));
                break;
            case DELETE_TARGET:
                statusContext.setTypeStatus(SpringContextHolder.getBean(DeleteTarget.class));
                break;
            case ARCHIVE_TARGET:
                statusContext.setTypeStatus(SpringContextHolder.getBean(FileTarget.class));
                break;
            case JOB_COUNT_TIME_START:
                statusContext.setTypeStatus(SpringContextHolder.getBean(JobStartLearn.class));
                break;
            case JOB_COUNT_TIME:
                statusContext.setTypeStatus(SpringContextHolder.getBean(JobCountTime.class));
                break;
            case TIME_LEARN_ROOMING:
                statusContext.setTypeStatus(SpringContextHolder.getBean(TimeLearnRoomStartLearn.class));
                break;
            case TIME_LEARN_ROOM_END:
                statusContext.setTypeStatus(SpringContextHolder.getBean(TimeLearnRoomEndLearn.class));
                break;
            default:
                throw new BusinessException(STATUS_HANDLER_ERROR.message);
        }
        return statusContext;
    }
}
